package com.onesports.intelligent.k12.polarlight.controller.operation.audit;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.framework.kit.common.result.PageResult;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.ApprovalDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseAdjustPriceRecordVO;
import com.onesports.intelligent.k12.polarlight.service.course.AdjustPriceRecordService;
import com.onesports.intelligent.k12.polarlight.service.course.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @author Wsy
 **/
@Api(tags = "运营端-审核管理API")
@RestController
@RequestMapping(ApiPathConstants.AUDIT_MANAGE)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class AuditManageController {

    private final CourseService courseService;
    private final AdjustPriceRecordService adjustPriceRecordService;

    @GetMapping("/adjust-record")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "row", value = "条数", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "organizationId", value = "申请团队id", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "campusId", value = "申请校区id", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "courseId", value = "申请课程id", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "auditStatus", value = "审核状态1:待审核 2：审核通过 3：审核不通过", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "auditBy", value = "审核人", paramType = "query", dataType = "string")
    })
    public ResponseEntity<PageResult<CourseAdjustPriceRecordVO>> adjustRecord(@NotNull(message = "请选择页数") Long page, @NotNull(message = "请选择每页条数") Long row,
                                                                              String organizationId, String campusId, String courseId, String auditStatus, String auditBy) {
        return ResultUtil.success(this.courseService.adjustRecord(new Page<>(page, row), organizationId, campusId, courseId, auditStatus, auditBy , null));
    }


    @PostMapping("/to-approval")
    @ApiOperation("审批")
    public ResponseEntity<String> toApproval(@Valid @RequestBody ApprovalDTO dto) {
        this.adjustPriceRecordService.toApproval(dto);
        return ResultUtil.success("操作成功");
    }
}
